package com.example.lib_cache.view_model;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.example.lib_cache.R;
import com.example.lib_cache.model.Story;

import java.util.ArrayList;

public class AFragmentViewModel extends ViewModel {

    private MutableLiveData<ArrayList<Story>> storiesLiveData;


    public MutableLiveData<ArrayList<Story>> getStoriesLiveData() {
        if (null==storiesLiveData){
            storiesLiveData=new MutableLiveData<>();
            initData();
        }
        return storiesLiveData;
    }

    private void initData() {
        //临时数据
        ArrayList<Story> mList=new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Story story = new Story("我是一个憨憨", R.mipmap.ic_chaoshi);
            mList.add(story);
        }
        storiesLiveData.setValue(mList);
    }
}
